package com.elinshaw;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

import java.util.Map;

/**
 * @author Administrator
 */
public class MoreThanBolt extends BaseRichBolt {

    private OutputCollector outputCollector;

    @Override
    public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
        this.outputCollector = outputCollector;
    }

    @Override
    public void execute(Tuple tuple) {
        //Tuple元组是一种kv结构用k取v
        Integer value = tuple.getIntegerByField("number");
        System.out.println("MoreThanBolt:" + value);
        Values values = new Values(value);
        outputCollector.emit("moreThan", values);
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        outputFieldsDeclarer.declareStream("moreThan", new Fields("number"));
        outputFieldsDeclarer.declareStream("lessThan", new Fields("number"));
    }


}
